﻿CREATE FUNCTION [dbo].[udf_GetDateAtMidnight]
(
	@TheDate datetime
)
RETURNS datetime
AS
BEGIN
	-- Declare the return variable here
	DECLARE @ReturnDate datetime

	-- Add the T-SQL statements to compute the return value here
	SELECT @ReturnDate = DATEADD(dd, DATEDIFF(dd,0,@TheDate), 0)

	-- Return the result of the function
	RETURN @ReturnDate

END